﻿#include "BaseInc.h"


float width = 640;
float height = 480;

void DoEvent(SDL_Event* evt)
{
	
}


int mains(int argc, char* argv[])
{
	int nRet = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
	SDL_Window* window = SDL_CreateWindow("base window", 200, 200, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, TRUE); // *new*
	SDL_Surface* surface = SDL_GetWindowSurface(window);
	SDL_Renderer* render = SDL_CreateRenderer(window, 0, SDL_VIDEO_RENDER_OGL);
	SDL_Texture* tex = SDL_CreateTexture(render, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, width, height);
	SDL_GLContext ctx = SDL_GL_CreateContext(window);
	SDL_Rect rect = {300,200,200,200};
	SDL_RenderSetViewport(render, &rect);
	surface =	SDL_LoadBMP("1.bmp");
	//SDL_RenderCopy(`)
	SDL_GL_MakeCurrent(window, ctx);
	SDL_Texture* tex1 = SDL_CreateTextureFromSurface(render, surface);
	SDL_Event evt;
	while (true)
	{
		SDL_WaitEvent(&evt);
		DoEvent(&evt);
		switch (evt.type) {
		case SDL_QUIT:
			break;
			break;
		}
		glViewport(0,100,100,100);

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(60, width / height, 0.1, 1000);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		glClear(GL_COLOR_BUFFER_BIT);
		glClear(GL_DEPTH_BUFFER_BIT);
		glClearColor(0.3, 0.3, 0.3, 1.);

		gluLookAt(0, 0, 100, 0, 0, 0, 0, 1, 0);

		glBegin(GL_QUADS);
			glColor3f(1.0, 1.0, 1.0); glVertex3f(0, 0, 0);
			glColor3f(1.0, 1.0, 0.0); glVertex3f(100, 0, 0);
			glColor3f(0.0, 1.0, 1.0); glVertex3f(100, 100, 0);
			glColor3f(0.0, 1.0, 1.0); glVertex3f(0, 100, 0);
		glEnd();

		SDL_GL_SwapWindow(window);
		SDL_RenderCopy(render, tex1, 0, 0);
		SDL_RenderPresent(render);
	
	}

	SDL_DestroyWindow(window);
//	SDL_CloseAudio();
	SDL_Quit();

	return 0;
}
